package com.ruoyi.web.controller.log.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.log.service.ILogService;
import com.ruoyi.model.log.LogEntity;
import com.ruoyi.model.log.dto.QueryLog;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 日志的Controller, 目前只能让用户查看日志
 */
@Api(tags = "日志管理")
@Slf4j
@RestController
@RequestMapping("/log")
public class LogController extends BaseController {

    @Autowired
    private ILogService iLogService;
    /**
     * 导出日志信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "日志信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QueryLog webLog)
    {
        List<LogEntity> list = iLogService.queryLogList(webLog);
        ExcelUtil<LogEntity> util = new ExcelUtil<LogEntity>(LogEntity.class);
        util.exportExcel(response, list, "日志信息数据");
    }

    /**
     * 通用日志查询接口
     * @return 查询结果对象
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo queryList(QueryLog queryLog) {
        startPage();
        List<LogEntity> list = iLogService.queryLogList(queryLog);
        return getDataTable(list);
    }
}
